﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Exam.Model
{
    public class ExamCollectionCls
    {
        public string ExamCollectionId;
        public string ExamCollectionName;
        public string Description;
        public string ParentExamCollectionId;
        public int SortIndex;
    }

    public class ExamCollectionParser
    {
        public static ExamCollectionCls CreateInstance()
        {
            //tao 1 class trang....
            ExamCollectionCls oExamCollectionCls = new ExamCollectionCls();
            return oExamCollectionCls;
        }

        public static ExamCollectionCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            ExamCollectionCls oExamCollectionCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oExamCollectionCls;
        }


        public static ExamCollectionCls ParseFromDataRow(DataRow dr)
        {
            ExamCollectionCls oExamCollectionCls = new ExamCollectionCls();
            oExamCollectionCls.ExamCollectionId = XmlUtility.GetString(dr, "ExamCollectionId", true);
            oExamCollectionCls.ExamCollectionName = XmlUtility.GetString(dr, "ExamCollectionName", true);
            oExamCollectionCls.Description = XmlUtility.GetString(dr, "Description", true);
            oExamCollectionCls.Description = XmlUtility.GetString(dr, "Description", true);
            oExamCollectionCls.ParentExamCollectionId = XmlUtility.GetString(dr, "frkParentExamCollectionId", true);
            oExamCollectionCls.SortIndex = XmlUtility.GetInt(dr, "SortIndex", true);

            return oExamCollectionCls;
        }

        public static ExamCollectionCls[] ParseFromDataTable(DataTable dtTable)
        {
            ExamCollectionCls[] ExamCollections = new ExamCollectionCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                ExamCollections[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return ExamCollections;
        }

        public static ExamCollectionCls[] ParseMultiRecordFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            if (ds.Tables.Count == 0)
            {
                return new ExamCollectionCls[0];
            }
            ExamCollectionCls[] ExamCollections = new ExamCollectionCls[ds.Tables[0].Rows.Count];
            for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
            {
                ExamCollections[iIndex] = ParseFromDataRow(ds.Tables[0].Rows[iIndex]);
            }
            return ExamCollections;
        }
    }
}

